package grailst
import winterwell.jtwitter.OAuthSignpostClient
import winterwell.jtwitter.Twitter
import winterwell.jtwitter.Twitter.Status

class PrincipalController {

    def index = { 
		
			redirect(action: "entrada", params: params)
		
	}
	
	def entrada = {
		if(session.usuario == null){
			redirect(action: "saida", params: params)
		}
		
		else{
			
		Twitter usuario = session.usuario
			
		Status men = usuario.getStatus()
		List<Status> twits = usuario.getUserTimeline()
		
		params.nome = usuario.getScreenName()
		params.status = men.toString()
		params.twits = twits
			
		}
	}
	
	def twit = {
		if(session.usuario == null){
			redirect(action: "saida", params: params)
		}
		
		else{
			Twitter usuario = session.usuario
			String mensagem = params.mensagem
			usuario.setStatus(mensagem)
			redirect(action: "entrada")
		}
	}
	
	def saida = {
		redirect(controller:'login',action:'index')
	}
	
	def logout = {
		if(session.usuario == null){
			redirect(action: "saida")
		}
		else{
			session.usuario = null
			redirect(controller:'login',action:'index')
		}
	}
	
}
